//
//  HDCFMangerMoneyController.m
//  HaoDeCaiFu
//
//  Created by 郑开宏 on 2017/10/28.
//  Copyright © 2017年 郑开宏. All rights reserved.
//

#import "HDCFMangerMoneyController.h"
#import "SDCycleScrollView.h"
#import "HDCFMMoneyGroupView.h"
#import "HDCFFundListVc.h"
#import "HDCFHDMMoneyVc.h"
#import "HttpRequest.h"
#import "SVProgressHUD.h"
#import "UIImageView+WebCache.h"
#import "HDCFImgLinkVc.h"

@interface HDCFMangerMoneyController ()<SDCycleScrollViewDelegate>

@property (nonatomic, strong)SDCycleScrollView *cycleScrollView;
@property (nonatomic, strong)NSMutableArray *imgArray;
@property (nonatomic, strong) NSArray *bannerJumpDataArray;
@property (nonatomic, strong) NSMutableArray *imgLinkUrl;
@property (nonatomic, strong) NSMutableArray *nameArray;
@end

@implementation HDCFMangerMoneyController

- (NSMutableArray *)imgLinkUrl{
    if (!_imgLinkUrl) {
        self.imgLinkUrl = [NSMutableArray array];
    }
    return _imgLinkUrl;
}

- (NSMutableArray *)imgArray{
    if (!_imgArray) {
        self.imgArray = [NSMutableArray array];
    }
    return _imgArray;
}

- (NSMutableArray *)nameArray{
    if (!_nameArray) {
        self.nameArray = [NSMutableArray array];
    }
    return _nameArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatView];
    
    //根据系统判断，让scrollview置顶显示
    //    if (@available(iOS 11.0, *)) {
    //        self.bottomScroll.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    //    } else {
    //        // Fallback on earlier versions
    //        self.automaticallyAdjustsScrollViewInsets = NO;
    //    }
    [self getData];
}

- (void)getData{
    [HttpRequest sendSelfGetRequestWithURL:@"api/SiteConfig/BannerList" WithParamets:nil success:^(id result) {
        if ([result[@"code"] isEqual:@1]) {
            self.bannerJumpDataArray = result[@"result"];
            for (int i = 0; i < self.bannerJumpDataArray.count; i++) {
                NSDictionary *dict = self.bannerJumpDataArray[i];
                NSString *strUrl = [NSString stringWithFormat:@"http://jx.chinahonden.xyz:15504%@", dict[@"Value"]];
                [self.imgArray addObject:strUrl];
                [self.imgLinkUrl addObject:dict[@"Value3"]];
                [self.nameArray addObject:dict[@"Name"]];
            }
            self.cycleScrollView.imageURLStringsGroup = self.imgArray;
        }else{
            //            [self getData];
        }
    } failure:^(NSError *errer) {
        [SVProgressHUD showErrorWithStatus:@"服务器错误"];
        [SVProgressHUD dismissWithDelay:1.0];
    }];
}

////banner图点击回调代理
//- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index{
//    NSLog(@"---");
//}

- (void)creatView{
    //轮播图
    
    CGFloat viewHeight = screenHeight - KNavHeight - 49;
     
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, screenWidth, viewHeight / 3) delegate:self placeholderImage:[UIImage imageNamed:@"5571512031951_.pic_hd.jpg"]];
    self.cycleScrollView.delegate = self;
    
    [self.view addSubview:self.cycleScrollView];
    
    
    UIScrollView * backScrollView = [[UIScrollView alloc]init];
    backScrollView.frame = CGRectMake(0, viewHeight/3, screenWidth, viewHeight/3*2);
    backScrollView.contentSize  = CGSizeMake(screenWidth, viewHeight);
    [self.view addSubview:backScrollView];
    
    
    HDCFMMoneyGroupView *viewOne = [HDCFMMoneyGroupView HDCFMMoneyGroupView];
    [viewOne.joinBtn setBackgroundColor:ZKcolor(250, 186, 76)];
    viewOne.joinBtn.tag = 100;
    [viewOne.joinBtn addTarget:self action:@selector(mangerMoneyBtnClick) forControlEvents:UIControlEventTouchUpInside];
    viewOne.frame = CGRectMake(5, 15, screenWidth - 10, viewHeight / 3 - 18);
    [backScrollView addSubview:viewOne];
    
    
    HDCFMMoneyGroupView *viewTwo = [HDCFMMoneyGroupView HDCFMMoneyGroupView];
    viewTwo.titleLabel.text = @"基金";
    viewTwo.imageV.image = [UIImage imageNamed:@"基金"];
    [viewTwo.joinBtn setBackgroundColor:ZKcolor(191, 130, 163)];
//    viewTwo.earningRatioLabel.text=@"117%";
    viewTwo.expectLabel.text=@"历史年化收益率";
    [viewTwo.joinBtn addTarget:self action:@selector(fundBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [viewTwo.joinBtn setTitle:@"火热抢购中" forState:UIControlStateNormal];
    viewTwo.frame = CGRectMake(5, viewHeight/ 3 + 3, screenWidth - 10, viewHeight / 3 - 8);
    [backScrollView addSubview:viewTwo];
    
    
    HDCFMMoneyGroupView *viewThree = [HDCFMMoneyGroupView HDCFMMoneyGroupView];
    viewThree.titleLabel.text = @"私募基金";
    viewThree.imageV.image = [UIImage imageNamed:@"私募基金"];
    [viewThree.joinBtn setBackgroundColor:ZKcolor(79, 137, 243)];
    //    viewTwo.earningRatioLabel.text=@"117%";
    viewThree.expectLabel.text=@"预期年化收益率（%）";
    viewThree.joinBtn.tag = 101;
    [viewThree.joinBtn addTarget:self action:@selector(fundOrderBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [viewThree.joinBtn setTitle:@"点击加入" forState:UIControlStateNormal];
    viewThree.frame = CGRectMake(5, viewHeight * 2 / 3 + 3, screenWidth - 10, viewHeight / 3 - 8);
    [backScrollView addSubview:viewThree];
}
//好得理财
- (void)mangerMoneyBtnClick{
    HDCFHDMMoneyVc *vc = [[HDCFHDMMoneyVc alloc] init];
    vc.fromID = 1;
    [self.navigationController pushViewController:vc animated:YES];
}
//基金列表
- (void)fundBtnClick{
    HDCFFundListVc *lictVc = [[HDCFFundListVc alloc] init];
    [self.navigationController pushViewController:lictVc animated:YES];
}
//私募基金
-(void)fundOrderBtnClick
{
    HDCFHDMMoneyVc *vc = [[HDCFHDMMoneyVc alloc] init];
    vc.fromID = 2;
    [self.navigationController pushViewController:vc animated:YES];
}

//轮播图点击图片回调
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    
    HDCFImgLinkVc *vc = [[HDCFImgLinkVc alloc] init];
    vc.imgLinkUrl = _imgLinkUrl[index];
    vc.name = _nameArray[index];
    [self.navigationController pushViewController:vc animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
